package com.base.service.impl;

import java.util.List;

import com.base.bean.Design;
import com.base.service.DesignService;
import com.common.util.AbstractManager;
import com.common.util.PagerModel;

public class DesignServiceImpl extends AbstractManager implements DesignService {

	public void addDesign(Design design) {
		String hql = "select nvl(max(designno),0) from Design";
		
		long designno = 0l;
		designno = (Long) this.getHibernateTemplate().find(hql).get(0);
		designno += 1l;
		
		design.setDesignno(designno);
		this.getHibernateTemplate().save(design);
	}

	@SuppressWarnings("unchecked")
	public List<Design> findAllDesign() {
		String hql = "from Design order by designno";
		return this.getHibernateTemplate().find(hql);
	}

	public Design findDesign(long designno) {
		return (Design) this.getHibernateTemplate().load(Design.class, designno);
	}

	public PagerModel findDesignForPager() {
		String hql = "from Design order by designno";
		return searchPaginated(hql);
	}

	public void removeDesign(long designno) {
		Design design = null;
		design = (Design) this.getHibernateTemplate().load(Design.class, designno);
		if(design != null) 
			this.getHibernateTemplate().delete(design);
	}

	public void updateDesign(Design design) {
		this.getHibernateTemplate().update(design);
	}
}
